package com.hightemperator.service;


import com.hightemperator.dao.BannerMapper;
import com.hightemperator.dao.SysBackgroundUserMapper;
import com.hightemperator.dao.SysUserMapper;
import com.hightemperator.po.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BackGroundUserService {

    @Resource
    private SysBackgroundUserMapper sysBackgroundUserMapper;
    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private BannerMapper bannerMapper;

    public List<SysBackgroundUser> getBackgroundUser(SysBackgroundUser sysBackgroundUser) {
        SysBackgroundUserExample example = new SysBackgroundUserExample();
        SysBackgroundUserExample.Criteria criteria = example.createCriteria();
        criteria.andUserAccountEqualTo(sysBackgroundUser.getUserAccount());
        criteria.andUserPasswordEqualTo(sysBackgroundUser.getUserPassword());
        return sysBackgroundUserMapper.selectByExample(example);
    }

    /**
     * 获取所有的用户列表
     * @param begin
     * @param end
     * @return
     */
    public Map<String,Object> getUserList(Integer begin, Integer end) {
        if (begin == 0 && end == 0) {
            begin = 0;
            end = Integer.MAX_VALUE;
        }
        List<SysUser> sysUserList = sysUserMapper.getUserList(begin, end);
        SysUserExample example = new SysUserExample();
        int count = sysUserMapper.countByExample(example);
        Map<String,Object> map  =new HashMap<>();
        map.put("list",sysUserList);
        map.put("count",count);
        return map;
    }

    /**
     * 添加banner图片
     * @param banner
     * @return
     */
    public int addBanner(Banner banner){
        int successcode = bannerMapper.insertSelective(banner);
        return successcode;
    }

}
